// routerGuard.jsx
import React from "react"
import { Route, Redirect, Switch } from "react-router-dom"

export const RenderRoutes = function({ routes }) {
  return (
    <Switch>
      { routes.map(route => (
        <Route 
          key={route.key}
          path={route.key}
          render={props => {
            return route.render ?
                        route.render({ ...props, route: route}) :
                        route.component && <route.component {...props} route={route} />
          }}
        />
      ))}
      <Redirect to={routes[0].key} />
    </Switch>
  )
}
